<?php

namespace Admin\Controller;

use Think\Controller;
use Admin\Model\GameModel;
use Admin\Model\LibaoModel;

class LibaoController extends Controller {

    private $gameModel;
    private $libaoModel;

    public function __construct() {
        parent::__construct();
        session("[start]");
        if (!isset($_SESSION['admininfo']) || $_SESSION['admininfo']['id'] < 1) {
            $this->redirect('Login/index');
        }
        $this->gameModel = new GameModel();
        $this->libaoModel = new LibaoModel();
    }

    public function index() {
        $gamelist = $this->gameModel->getGameList();
        $this->assign('gamelist', $gamelist);
        $this->display();
    }

    public function post() {
        $type = I('request.type');
        $game_id = intval($_REQUEST['game_id']);
        $game = $this->gameModel->getGameById($game_id);
        if (IS_POST) {
            $data['game_id'] = $game_id;
            $data['chname'] = I('post.chname');
            $data['enname'] = I('post.tag'); //礼包英文名
            $data['gamename'] = I('post.gamename');
            $data['general'] = I('post.general');
            $data['port'] = I('post.port');
            $data['details'] = $_POST['details'];
            $data['operation'] = $_POST['operation'];
            if($this->libaoModel->add($data)){
                $this->success('礼包设置成功',U('libao/index'));
            }else{
                $this->success('礼包设置失败',U('libao/index'));
            }
        }



        $this->assign('game', $game);
        $this->assign('game_id', $game_id);
        $this->display();
    }

}
